package com.heima.behavior.listener;

import com.alibaba.fastjson.JSON;
import com.heima.behavior.dto.FollowBehaviorDto;
import com.heima.behavior.service.IApFollowBehaviorService;
import org.apache.commons.lang3.StringUtils;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

@Service
public class FollowListener {

    @Autowired
    private IApFollowBehaviorService iApFollowBehaviorService;

    @KafkaListener(topics = "${topic.followBehaviorTopic}")
    public void handleMsg(ConsumerRecord<String, String> record) {
        String value = record.value();
        if (StringUtils.isNotEmpty(value)) {
            FollowBehaviorDto dto = JSON.parseObject(value, FollowBehaviorDto.class);
            iApFollowBehaviorService.saveBehavior(dto);
        }
    }
}
